/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package main.environment;

import main.common.Tile;

/**
 *
 * @author Fox
 */
public class Location {
    
    private int x;
    private int y;
    private Tile owner;
    private boolean bounded = true;
    
    private int bounds(int v) {
        return v;//Math.min(Math.max(v,0),31);
    }
    
    public Location(int x, int y){
        this.x = x;
        this.y = y;
    }
    
    public Location(int x, int y, Tile owner){
        this.owner = owner;
        this.x = x;
        this.y = y;
    }
    
    public Location(Location l, int plusX, int plusY) {
        this.owner = l.getOwner();
        this.x = l.getX()+plusX;
        this.y = l.getY()+plusY;
        
        if (l.isBounded()) {
            x = bounds(x);
            y = bounds(y);
        }
    }

    public boolean isBounded() {
        return bounded;
    }

    public void setBounded(boolean bounded) {
        this.bounded = bounded;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = bounds(x);
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = bounds(y);
    }    

    public Tile getOwner() {
        return owner;
    }

    public void setOwner(Tile owner) {
        this.owner = owner;
    }
    
    public LevelChange getChange() {
        if (x<0) {
            x=31;
            return new LevelChange(-1,0);
        } else {
            if (x>31) { 
                x=0;
                return new LevelChange(1,0);
            } else {
                if (y<0) {
                    y=31;
                    return new LevelChange(0,-1);
                } else {
                    if (y>31) {
                        y=0;
                        return new LevelChange(0,1);
                    }
                }
            }
        }
        
        return null;
    }
}
